// pages/sign-in/sign-in.js
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabselect: 0,
    work_status: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    var query = wx.createSelectorQuery();
    //选择id
    query.select('#nav').boundingClientRect()
    query.exec(function(res) {
      console.log(res[0].height);
      that.setData({
        scrollViewHeigth: wx.getSystemInfoSync().windowHeight - res[0].height,
      })
    })

    this.setData({
      windowWidth: app.globalData.windowWidth,
      date: new Date(),
    });

    this.loadMemberList();
  },

  selectTab: function(e) {
    if (e.currentTarget.dataset.idx != this.data.tabselect) {
      this.setData({
        tabselect: e.currentTarget.dataset.idx
      })
    }
  },

  //滑动切换
  swiperTab: function(e) {
    var that = this;
    that.setData({
      tabselect: e.detail.current,
    });
  },

  //点击切换
  clickTab: function(e) {
    if (e.currentTarget.dataset.idx != this.data.tabselect) {
      this.setData({
        tabselect: e.currentTarget.dataset.idx
      })
    }
  },

  loadMemberList: function() {
    wx.showLoading({
      title: '加载中...',
      mask: true
    })
    var data = {
      point_url: app.server.adminApi.getWorkStatus,
    };
    var that = this;

    app.server.getConnect(data).then(function(res) {
      console.log(res.data);
      var signedList = [];
      var unSignList = [];
      for (var i in res.data) {
        if (!res.data[i].work_time) {
          unSignList.push(res.data[i]);
        } else {
          var workDate = res.data[i].work_time.substr(0, 10).split("-");
          if (workDate[0] == that.data.date.getFullYear() && workDate[1] == (that.data.date.getMonth() + 1) && workDate[2] == that.data.date.getDate()) {
            res.data[i].work_time = res.data[i].work_time.substr(11, 8);
            if (res.data[i].hiredate) {
              res.data[i].hiredate = res.data[i].hiredate.substr(0, 10);
            }
            signedList.push(res.data[i]);
          } else {
            unSignList.push(res.data[i]);
          }
        }
      }

      that.setData({
        signedList: signedList,
        unSignList: unSignList
      });
      wx.hideLoading();
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    app.pageOnloadInit(this, app);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    wx.setNavigationBarTitle({
      title: '签到',
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    app.pageOnloadInit(this, app);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})
